package com.example.springbootprinciple.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringApplicationRunListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

public class MyHelloSpringApplicationRunListener implements SpringApplicationRunListener {

    Logger logger = LoggerFactory.getLogger(getClass());

    /**
     * 规定构造方法必须接收 SpringApplication application, String[] args 这两个参数
     * @param application
     * @param args
     */
    public MyHelloSpringApplicationRunListener(SpringApplication application, String[] args) {
        logger.info("MyHelloSpringApplicationRunListener的构造器，SpringApplication = "+application);
    }

    @Override
    public void starting() {
        logger.info("MyHelloSpringApplicationRunListener---starting ========");
    }

    @Override
    public void environmentPrepared(ConfigurableEnvironment environment) {
        logger.info("MyHelloSpringApplicationRunListener---environmentPrepared ========根据环境获取属性，操作系统的名字 \t"+environment.getPropertySources().get("os.name"));

    }

    @Override
    public void contextPrepared(ConfigurableApplicationContext context) {
        logger.info("MyHelloSpringApplicationRunListener---contextPrepared ========");

    }

    @Override
    public void contextLoaded(ConfigurableApplicationContext context) {
        logger.info("MyHelloSpringApplicationRunListener---contextLoaded ========");

    }

    @Override
    public void started(ConfigurableApplicationContext context) {
        logger.info("MyHelloSpringApplicationRunListener---started ========");

    }

    @Override
    public void running(ConfigurableApplicationContext context) {
        logger.info("MyHelloSpringApplicationRunListener---running ========");

    }

    @Override
    public void failed(ConfigurableApplicationContext context, Throwable exception) {
        logger.info("MyHelloSpringApplicationRunListener---failed ========");

    }
}
